// ----------------------------------
// RSDK Project: Sonic Essence
// Script Description: Fence
// Script Author: Tails LP, Xanman
// ----------------------------------

// Aliases
private alias 24 : TYPE_WATERFALL

// Function declarations
reserve function Fence_DebugDraw
reserve function Fence_DebugSpawn

function Fence_DebugDraw
	DrawSprite(0)
end function


function Fence_DebugSpawn
	CreateTempObject(TypeName[Fence], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 6
end function


event ObjectMain
	object.priority = PRIORITY_ACTIVE
end event


event ObjectDraw
	object.inkEffect = INK_ALPHA
	object.alpha = 140
		object.value2++

		if object.value2 >= 4
			if object.frame <= 2
				object.frame++
				object.value2 = 0
			else
				object.frame = 0
				object.value2 = 0
			end if
		end if

		object.value3 = object.frame
		object.value3 += 4

		object.value4 = object.frame
		object.value4 += 8

		temp3 = 0
		temp4 = 0
		while temp3 <= object.value0

			temp0 = object.xpos
			temp1 = 0x200000
			temp1 *= temp3
			temp0 += temp1
			temp2 = object.value0
			temp0 -= temp2

			while temp4 <= object.value1
				temp5 = object.ypos
				temp6 = 0x200000
				temp6 *= temp4
				temp5 -= temp6
				temp7 = object.value1
				temp5 += temp7

				DrawSpriteFX(object.frame, FX_INK, temp0, temp5)
				if temp4 == 0
					DrawSpriteFX(object.value4, FX_INK,temp0, temp5)
				end if
				temp4 ++
			loop

			DrawSpriteFX(object.value3, FX_INK, temp0, temp5)

			temp4 = 0

			temp3 ++
		loop
end event


event ObjectStartup

	LoadSpriteSheet("SSZ/Objects.gif")

	foreach (TypeName[Waterfall], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].priority = PRIORITY_ACTIVE
	next



	// Ring frames

	SpriteFrame(-16, -16, 32, 32, 1, 185) //0
	SpriteFrame(-16, -16, 32, 32, 34, 185)
	SpriteFrame(-16, -16, 32, 32, 67, 185)
	SpriteFrame(-16, -16, 32, 32, 100, 185)

	SpriteFrame(-16, -32, 32, 16, 1, 235) //4
	SpriteFrame(-16, -32, 32, 16, 34, 235)
	SpriteFrame(-16, -32, 32, 16, 67, 235)
	SpriteFrame(-16, -32, 32, 16, 100, 235)
	
	SpriteFrame(-16, 16, 32, 16, 1, 218) //8
	SpriteFrame(-16, 16, 32, 16, 34, 218)
	SpriteFrame(-16, 16, 32, 16, 67, 218)
	SpriteFrame(-16, 16, 32, 16, 100, 218)


	// Add the Ring to the debug mode object list
	SetTableValue(TypeName[Fence], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(Fence_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Fence_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
	
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
